<?php

require_once 'PHPUnit/Extensions/ExceptionTestCase.php';
jClasses::inc('cube~Cube');

// Test of the limits of the Cubie construct
class UTCube extends PHPUnit_Extensions_ExceptionTestCase 
{
    public function testConstruct() 
    {
        try 
        {
            $myCube = new Cube();
        }
        catch (Exception $e) {$this->fail('Cube constructor test');}
    }

    public function testToString() 
    {
        $myCube   = new Cube();
        $mystring = $myCube->__toString();
        $this->assertEquals($mystring, '(1 2 3 4 5 6) (1 2 3 4 5 6 7 8 9 10 11 12) (1 2 3 4 5 6 7 8)');
    }

    public function testTurn() 
    {
        $myCube = new Cube();
        $myCube->turn('U');
        $mystring = $myCube->__toString();
        $this->assertEquals($mystring, '(1 2 3 4 5 6) (2 3 4 1 5 6 7 8 9 10 11 12) (2 3 4 1 5 6 7 8)');

        $myCube = new Cube();
        $myCube->turn('R');
        $mystring = $myCube->__toString();
        $this->assertEquals($mystring, '(1 2 3 4 5 6) (1 6- 3 4 5 10- 2- 8 9 7- 11 12) (1 6- 2+ 4 5 7+ 3- 8)');

        $myCube = new Cube();
        $myCube->turn('B');
        $mystring = $myCube->__toString();
        $this->assertEquals($mystring, '(1 2 3 4 5 6) (1 2 7 4 5 6 11 3 9 10 8 12) (1 2 7- 3+ 5 6 8+ 4-)');

        $myCube = new Cube();
        $myCube->turn('L');
        $mystring = $myCube->__toString();
        $this->assertEquals($mystring, '(1 2 3 4 5 6) (1 2 3 8- 4- 6 7 12- 9 10 11 5-) (4+ 2 3 8- 1- 6 7 5+)');

        $myCube = new Cube();
        $myCube->turn('F');
        $mystring = $myCube->__toString();
        $this->assertEquals($mystring, '(1 2 3 4 5 6) (5 2 3 4 9 1 7 8 6 10 11 12) (5- 1+ 3 4 6+ 2- 7 8)');

        $myCube = new Cube();
        $myCube->turn('D');
        $mystring = $myCube->__toString();
        $this->assertEquals($mystring, '(1 2 3 4 5 6) (1 2 3 4 5 6 7 8 12 9 10 11) (1 2 3 4 8 5 6 7)');

        $myCube = new Cube();
        $myCube->turn('M');
        $mystring = $myCube->__toString();
        $this->assertEquals($mystring, '(4 1 3 6 5 2) (3- 2 11- 4 5 6 7 8 1- 10 9- 12) (1 2 3 4 5 6 7 8)');

        $myCube = new Cube();
        $myCube->turn('E');
        $mystring = $myCube->__toString();
        $this->assertEquals($mystring, '(1 5 2 3 4 6) (1 2 3 4 8- 5- 6- 7- 9 10 11 12) (1 2 3 4 5 6 7 8)');

        $myCube = new Cube();
        $myCube->turn('S');
        $mystring = $myCube->__toString();
        $this->assertEquals($mystring, '(5 2 1 4 6 3) (1 4- 3 12- 5 6 7 8 9 2- 11 10-) (1 2 3 4 5 6 7 8)');

        // R2 U R U R' U' R' U' R' U R'
        $myCube = new Cube();
        $myCube->turn('R');
        $myCube->turn('R'); // R2
        $myCube->turn('U');
        $myCube->turn('R');
        $myCube->turn('U');
        $myCube->turn('R');
        $myCube->turn('R');
        $myCube->turn('R'); // R'
        $myCube->turn('U');
        $myCube->turn('U');
        $myCube->turn('U'); // U'
        $myCube->turn('R');
        $myCube->turn('R');
        $myCube->turn('R'); // R'
        $myCube->turn('U');
        $myCube->turn('U');
        $myCube->turn('U'); // U'
        $myCube->turn('R');
        $myCube->turn('R');
        $myCube->turn('R'); // R'
        $myCube->turn('U'); // U
        $myCube->turn('R');
        $myCube->turn('R');
        $myCube->turn('R'); // R'
        $mystring = $myCube->__toString();
        $this->assertEquals($mystring, '(1 2 3 4 5 6) (2 4 3 1 5 6 7 8 9 10 11 12) (1 2 3 4 5 6 7 8)');
    }

    public function testDummyTurn()
    {
        $myCube = new Cube();
        $this->setExpectedException('Exception');
        $myCube->turn('dummy');
    }

    public function testGetState()
    {
        $myCube = new Cube();
        $myCube->getState();
        // TODO properly test this method
    }

    public function testGetPiece()
    {
        $this->markTestIncomplete('Test to be completed');
        $cube  = new Cube();
        $piece = $cube->getPiece('center',  6);
        $this->assertTrue(is_array($piece));
        $this->assertTrue(array_key_exists('origin', $piece));
        $this->assertTrue(array_key_exists('orientation', $piece));
        $this->assertTrue(is_int($piece['origin']));
        $this->assertTrue(is_int($piece['orientation']));
        $this->assertEquals(6, $piece['origin']);
        $this->assertEquals(0, $piece['orientation']);

        $piece = $cube->getPiece('edge' , 12);
        $this->assertEquals(12, $piece['origin']);
        $this->assertEquals(0, $piece['orientation']);

        $piece = $cube->getPiece('corner',  8);
        $this->assertEquals(8, $piece['origin']);
        $this->assertEquals(0, $piece['orientation']);
    }

    public function testGetColor()
    {
        $this->markTestIncomplete('Test to be completed');
        $cube  = new Cube();
        $color = $cube->getColor('corner', 8, 2);
        $this->assertEquals($color, Cube::COLOR_B);
    }

    public function testAlg()
    {
        $myCube = new Cube();
        $myCube->alg("R R U R U R R R U U U R R R U U U R R R U R R R");
        $mystring = $myCube->__toString();
        $this->assertEquals($mystring, '(1 2 3 4 5 6) (2 4 3 1 5 6 7 8 9 10 11 12) (1 2 3 4 5 6 7 8)');
    }
}
?>
